package message.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class JsonUtils {
    public static Map<String, Object> getJavaDict(JSONObject jsonObj) {
        Map<String, Object> dict = new HashMap();
        Iterator var3 = jsonObj.entrySet().iterator();

        while (var3.hasNext()) {
            Entry entry = (Entry) var3.next();
            String key = (String) entry.getKey();
            Object value = entry.getValue();
            if (value == null) {
                dict.put(key, (Object) null);
            } else if (value.getClass() == JSONArray.class) {
                dict.put(key, getJavaList((JSONArray) value));
            } else if (value.getClass() == JSONObject.class) {
                dict.put(key, getJavaDict((JSONObject) value));
            } else {
                dict.put(key, value);
            }
        }

        return dict;
    }

    public static List<Object> getJavaList(JSONArray seq) {
        List<Object> list = new ArrayList();

        for (int i = 0; i < seq.size(); ++i) {
            Object value = seq.get(i);
            if (value == null) {
                list.add((Object) null);
            } else if (value.getClass() == JSONArray.class) {
                list.add(getJavaList((JSONArray) value));
            } else if (value.getClass() == JSONObject.class) {
                list.add(getJavaDict((JSONObject) value));
            } else {
                list.add(value);
            }
        }

        return list;
    }
}
